package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.system.domain.QyEnterpriseProductionType;
import com.ruoyi.system.service.IQyEnterpriseProductionTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产类型Controller
 *
 * @author yy
 * @date 2021-12-15
 */
@Api(tags = " 生产类型")
@RestController
@RequestMapping("/qyEnterpriseProductionType")
public class QyEnterpriseProductionTypeController extends BaseController {
    @Autowired
    private IQyEnterpriseProductionTypeService qyEnterpriseProductionTypeService;

    /**
     * 查询生产类型列表
     */
    @ApiOperation(value="查询生产类型列表", notes="查询生产类型列表")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:list")
    @GetMapping("/list")
    public TableDataInfo list(QyEnterpriseProductionType qyEnterpriseProductionType) {
        startPage();
        List<QyEnterpriseProductionType> list = qyEnterpriseProductionTypeService.selectQyEnterpriseProductionTypeList(qyEnterpriseProductionType);
        return getDataTable(list);
    }

    /**
     * 导出生产类型列表
     */
    @ApiOperation(value="导出生产类型列表", notes="导出生产类型列表")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:export")
    @Log(title = "生产类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QyEnterpriseProductionType qyEnterpriseProductionType) throws IOException {
        List<QyEnterpriseProductionType> list = qyEnterpriseProductionTypeService.selectQyEnterpriseProductionTypeList(qyEnterpriseProductionType);
        ExcelUtil<QyEnterpriseProductionType> util = new ExcelUtil<QyEnterpriseProductionType>(QyEnterpriseProductionType.class);
        util.exportExcel(response, list, "生产类型数据");
    }
    /**
     * 获取生产类型详细信息
     */
    @ApiOperation(value="获取生产类型详细信息", notes="获取生产类型详细信息")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(qyEnterpriseProductionTypeService.selectQyEnterpriseProductionTypeById(id));
    }

    /**
     * 新增生产类型
     */
    @ApiOperation(value="新增生产类型", notes="新增生产类型")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:add")
    @Log(title = "生产类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QyEnterpriseProductionType qyEnterpriseProductionType) {
        List<QyEnterpriseProductionType>  qyEnterpriseProductionTypes= qyEnterpriseProductionTypeService.selectQyEnterpriseProductionTypeList(qyEnterpriseProductionType);
        if (qyEnterpriseProductionTypes.size()>0){
            return AjaxResult.error("已存在名称为"+qyEnterpriseProductionTypes.get(0).getProName()+"的类型");
        }else {
            return toAjax(qyEnterpriseProductionTypeService.insertQyEnterpriseProductionType(qyEnterpriseProductionType));
        }
    }

    /**
     * 修改生产类型
     */
    @ApiOperation(value="修改生产类型", notes="修改生产类型")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:edit")
    @Log(title = "生产类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QyEnterpriseProductionType qyEnterpriseProductionType) {
        return toAjax(qyEnterpriseProductionTypeService.updateQyEnterpriseProductionType(qyEnterpriseProductionType));
    }

    /**
     * 删除生产类型
     */
    @ApiOperation(value="删除生产类型", notes="删除生产类型")
    @ApiImplicitParam(name = "ids", value = "生产类型ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "system:qyEnterpriseProductionType:remove")
    @Log(title = "生产类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qyEnterpriseProductionTypeService.deleteQyEnterpriseProductionTypeByIds(ids));
    }
}
